Add mod list sorting system#971
Conversation
ModsFolder.getModsList now has an optional parameter to describe the various sorting options. Excluding this option produces rather legacy behavior and should be backwards-compatible. Sorted mod lists get cached under a so-called "sort forge," which writes the key to use in the cache. If a cache hit occurs, then ModsFolder.getModsList will use the hit. Currently, there is support for ascending/descending order and two modes: clean and alphabetical sorting. Clean mode provides legacy behavior using this new system, and alphabetical sorting uses CoolUtil to sort the list. ModSwitchMenu has been updated to use this new system, but really, the only noticeable change should just be additional memory overhead.
|
This is currently set as a draft pull request, because there's one tiny change I want to make, and that is to move the mode ID function over to the controller. However, it's likely going to come tomorrow where I'm at, since it's getting far too late as I'm writing this. |
|
The mode ID is now assigned by using a string abstract enum, alongside a new delimiter for each mod in the sort forge. |
|
Is there any example usage of this? |
Sorting does get used in the regular mod switch menu here if that's what you're referring to, though it essentially functions the same way it did before the change, since there's no added way to change the sorting ingame at the moment: mods = ModsFolder.getModsList({
descending: false,
mode: CLEAN,
}); |
|
If we're considering this, might aswell do it to addons too and add a way to change the sorting here |
Hm, addons are currently just treated as libraries and |
The mods list can now be sorted in-engine with a cache to come with it.
From the commit message:
The primary use case for this would be for extending the mods switch menu to support multiple sorting options, all while being performant in the long run, especially with larger mods lists. The caching in particular assists in this by avoiding the overuse of sorting, doing so only once.
The system should be able to add more sorting mechanisms easily, just by adding the mode to the main enumerator and adding support for the mode in
ModSortingController. Of course, this does believe that the raw output of the sort is in ascending order, as descending order takes higher priority. These likely will need to come in succeeding pull requests, though, since (as of writing) I don't have any plans to add additional sorting modes in this pull request.